<template>
  <div class="container">
    <!--顶部广告区-->
    <div class="top-banner">
        <img src="@/assets/img/banner.png" alt="图片正在奔跑，速度八十迈">
    </div>
    <!--中间概览区-->
    <div class="middle-overview">
        <div class="left">
          <img src="@/assets/img/book2.png" alt="图片正在狂飙">
        </div>
        <div class="right">
            <h1>{{ articleInfo.title }}</h1>
            <span class="author">作者：{{articleInfo.author}}</span>
            <span class="category">分类：<el-tag :type="categoryColor()">{{articleInfo.category}}</el-tag></span>
            <p class="intro">
              {{articleInfo.intro}}
            </p>
            <div class="read">
              <button @click="toDetail($route.query.id)">阅读</button>
            </div>
        </div>
    </div>
    <!--底部目录区-->
    <div class="bottom-catalogue">
      <h1>目录</h1>
    </div>
  </div>
</template>

<script>
import {findArticleApi} from "@/api/article"
export default {
  name: "",
  data() {
    return {
      articleInfo: {
        intro: null,
        category: null
      }
    }
  },
  methods: {
    // 跳转到详情页
    toDetail(id){
      this.$router.push({
        path: '/library/detail',
        query: {
          id: id
        }
      })
    },
    // 查询文章信息
    selectArticleInfo(id){
      findArticleApi(id).then((res) => {
        this.articleInfo = res.data;
        console.log(res);
      })
    },
    // 选择分类的样式颜色
    categoryColor(){
      if (this.articleInfo.category === '前端'){
        return 'success';
      }else if (this.articleInfo.category === '后端'){
        return 'warning';
      }else if (this.articleInfo.category === '大数据'){
        return 'danger';
      }else {
        return '';
      }
    }
  },
  created() {
    this.selectArticleInfo(this.$route.query.id)
  }
}
</script>

<style scoped lang="scss">
.container {
  width: 1200px;
  margin: 20px auto 0;
  // 顶部 广告图
  .top-banner {
    padding: 15px 0;
    height: 80px;
    background-color: white;
    img {
      margin: 0 auto;
      width: 1150px;
      height: 80px;
      border-radius: 5px;
    }
  }
  // 中间 概述部分
  .middle-overview {
    margin: 30px 0;
    background-color: white;
    height: 300px;
    .left {
      float: left;
      margin: 50px 50px;
      img {
        width: 145px;
        height: 200px;
      }
    }
    .right {
      float: left;
      width: 900px;
      h1 {
        font-size: 25px;
        font-weight: 345;
        margin-top: 60px;
      }
      .author {
        font-size: 15px;
        margin-top: 15px;
        margin-right: 25px;
      }
      .category {
        font-size: 15px;
        margin-top: 15px;
      }
      .intro {
        font-size: 15px;
        margin-top: 15px;
        height: 80px;
        overflow: hidden;
      }
      .read {
        button {
          float: right;
          cursor: pointer;
          font-size: 16px;
          color: white;
          background-color: #3284fa;
          width: 100px;
          height: 30px;
          border-radius: 5px;
        }
      }
      .read::after {
        display: block;
        content: '';
        clear: both;
      }

    }
  }
  .middle-overview::after {
    display: block;
    content: '';
    clear: both;
  }

  .bottom-catalogue {
    // 暂时写上，实际由内容撑开
    height: 200px;
    background-color: white;
    padding: 50px;
    h1 {
      font-size: 20px;
      font-weight: 300;
    }
  }
}

</style>